package com.wwt.blog.controller;

import com.wwt.blog.aop.Cache;
import com.wwt.blog.service.ArticleService;
import com.wwt.blog.vo.Result;
import com.wwt.blog.vo.param.ArticleParam;
import com.wwt.blog.vo.param.PageParams;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;


@Log4j2
@RestController //返回的是JSON数据类型
@RequestMapping("/articles")
public class ArticleController {
    /**
     * Description:首页文章列表
     */
    @Autowired
    private ArticleService articleService;
    @PostMapping
    //@Cache(value = "listArticles",expire = 1*60*1000)
    public Result listArticles( @RequestBody PageParams pageParams ){

        return articleService.listArticles(pageParams);
    }
    /**
     * 首页最热文章的实现
     */
    @PostMapping("/hot")
    @Cache(value = "hot",expire = 10*60*1000)
    public Result getHotArticles(){
        return Result.result_success(articleService.getHotArticles());
    }
    /**
     * 首页最新文章的实现
     */
    @PostMapping("/new")
    @Cache(value = "new",expire = 10*60*1000)
    public Result getNewArticles(){
        int  limit=5;  //限制显示条数
        return Result.result_success(articleService.getNewArticles(limit));
    }
    /**
     * 首页文章归类的实现
     */
    @PostMapping("/listArchives")
    public Result getListArchives(){
        return articleService.getListArchives();
    }
    /**
     * 文章详情的实现
     */
    @PostMapping("/view/{id}")
    public Result findArticleBodyById(@PathVariable("id") Long articleId){
        return articleService.getArticleBodyById(articleId);
    }
    /**
     * 发表文章
     */
    @PostMapping("/publish")
    public Result articlePublish(@RequestBody ArticleParam articleParam){

        return articleService.articlePublish(articleParam);
    }

}
